﻿using System;
using System.Collections.Generic;
using System.Text;


using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
using OT.Module.ModelConst;
using OT.Common;
using OT.EntLib.Validate;

namespace OT.Module.Model
{
    [OptimisticLocking(false)]
    [Persistent(GDB.Order)]
    public partial class Order : XPLiteObject
    {
        #region ~

        /// <summary>
        /// 构造函数
        /// </summary>
        public Order() : base ( new Session() )
        {

        }

        public Order(Session s)
            : base(s)
        {
        }

        public Order(Session s, XPClassInfo info)
            : base(s, info)
        {
        }

        #endregion

        #region ID

        private string _ID = "";
        /// <summary>
        /// 
        /// </summary>
        /// 
        [Key(false)]
        public string ID
        {
            get
            {
                return _ID;
            }
            set
            {
                SetPropertyValue("ID", ref _ID, value);
            }
        }
        #endregion
                
        #region OrderCode  订单编号

        private string _OrderCode = "";

        [StringLengthValidator(GConst.NameMinLen, GConst.NameMaxLen,
          MessageTemplate = MsgUtility.StringLength, Tag = GSyntax.Order.OrderCode)]
        [DisplayName(GSyntax.Order.OrderCode), Size(GConst.NameMaxLen)]
        public string OrderCode
        {
            get
            {
                return _OrderCode;
            }
            set
            {
                SetPropertyValue("OrderCode", ref _OrderCode, value);
            }
        }

        #endregion

        #region OwnerName  客户名称

        private string _OwnerName = "";

        [StringLengthValidator(GConst.NameMinLen, GConst.NameMaxLen,
            MessageTemplate = MsgUtility.StringLength, Tag = GSyntax.Order.OwnerName)]
        [DisplayName(GSyntax.Order.OwnerName), Size(GConst.NameMaxLen)]
        public string OwnerName
        {
            get { return _OwnerName; }
            set { SetPropertyValue("OwnerName", ref _OwnerName, value); }
        }

        #endregion
        
        #region ContactPhone  联系方式

        private string _ContactPhone = "";

        [StringLengthValidator(GConst.NameMinLen, GConst.NameMaxLen,
            MessageTemplate = MsgUtility.StringLength, Tag = GSyntax.Order.ContactPhone)]
        [DisplayName(GSyntax.Order.ContactPhone), Size(GConst.NameMaxLen)]
        public string ContactPhone
        {
            get { return _ContactPhone; }
            set { SetPropertyValue("ContactPhone", ref _ContactPhone, value); }
        }

        #endregion

        #region OrderTime  下单时间

        [Persistent("OrderTime")]
        private DateTime _OrderTime = DateTime.Now;

        [PersistentAlias("_OrderTime")]
        [DisplayName(GSyntax.Order.OrderTime)]
        public DateTime OrderTime
        {
            get
            {
                return _OrderTime;
            }
        }

        #endregion

        #region OrderDetails  订单明细

        [Association("Order-OrderDetails", typeof(OrderDetail)), Aggregated]
        public XPCollection<OrderDetail> OrderDetails { get { return GetCollection<OrderDetail>("OrderDetails"); } }

        #endregion

    }
}
